<html>
<head><meta charset="utf-8"><title>associated types? · z-archived-t-compiler/wg-rls-2.0/chalk · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/index.html">z-archived-t-compiler/wg-rls-2.0/chalk</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html">associated types?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="166200629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166200629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166200629">(May 21 2019 at 18:43)</a>:</h4>
<p>Should this work?</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">I</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">I</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">i32</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">next</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Option</span><span class="o">&lt;</span><span class="n">Self</span>::<span class="n">Item</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">None</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">I</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">I</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">s</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p><code>foo</code> is resolved properly, but not <code>s</code></p>



<a name="166200653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166200653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166200653">(May 21 2019 at 18:43)</a>:</h4>
<p>also, <code>Self::Item</code> isn't handled properly</p>



<a name="166201221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166201221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166201221">(May 21 2019 at 18:50)</a>:</h4>
<p>No, projecting associated types isn't implemented yet. I'm working on it at the moment :)</p>



<a name="166201300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166201300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166201300">(May 21 2019 at 18:51)</a>:</h4>
<p>nor does it work with <code>-&gt; Option&lt;i32&gt;</code>, FWIW</p>



<a name="166201313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166201313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166201313">(May 21 2019 at 18:51)</a>:</h4>
<p><del>also, just defining <code>Iterator</code> doesn't work of course... rust actually seems to hardcode a desugaring using <code>::std::iter::IntoIterator::into_iter</code> </del><br>
I misread your code ;)</p>



<a name="166201441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166201441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166201441">(May 21 2019 at 18:52)</a>:</h4>
<p>but yeah, for loops aren't implemented yet at all</p>



<a name="166201467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166201467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166201467">(May 21 2019 at 18:53)</a>:</h4>
<p><span aria-label="grimacing" class="emoji emoji-1f62c" role="img" title="grimacing">:grimacing:</span></p>



<a name="166201491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166201491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166201491">(May 21 2019 at 18:53)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">S</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">Self</span>::<span class="n">bar</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="166201496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166201496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166201496">(May 21 2019 at 18:53)</a>:</h4>
<p>This doesn't work either</p>



<a name="166201508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166201508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166201508">(May 21 2019 at 18:53)</a>:</h4>
<p>Thought it was implemented in <a href="https://github.com/rust-analyzer/rust-analyzer/pull/912/" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/pull/912/">https://github.com/rust-analyzer/rust-analyzer/pull/912/</a></p>



<a name="166201629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166201629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166201629">(May 21 2019 at 18:55)</a>:</h4>
<p>At least that's not related to Chalk</p>



<a name="166203761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166203761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166203761">(May 21 2019 at 19:20)</a>:</h4>
<p>yeah, that's <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir/src/ty/infer.rs#L499" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir/src/ty/infer.rs#L499">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir/src/ty/infer.rs#L499</a></p>



<a name="166205286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/166205286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#166205286">(May 21 2019 at 19:36)</a>:</h4>
<p>Ah</p>



<a name="168050560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated%20types%3F/near/168050560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/191167-z-archived-t-compiler/wg-rls-2.0/chalk/topic/associated.20types.3F.html#168050560">(Jun 13 2019 at 14:33)</a>:</h4>
<p>I'll probably get the associated types / Deref support done this weekend, btw... Currently investigating why we don't find the <code>impl&lt;T&gt; Deref for Arc&lt;T&gt;</code> for some reason :( or rather we find it, but ignore it because we can't resolve <code>Deref</code> there.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>